package com.ruoyi.system.service.impl;

import java.math.BigDecimal;
import java.util.List;

import com.ruoyi.common.core.utils.ServletUtils;
import com.ruoyi.common.security.service.TokenService;
import com.ruoyi.system.api.model.LoginUser;
import com.ruoyi.system.domain.SysUserScok;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.StockMapper;
import com.ruoyi.system.domain.Stock;
import com.ruoyi.system.service.IStockService;

/**
 * 股票列表增删改查Service业务层处理
 * 
 * @author majingqi
 * @date 2024-06-20
 */
@Service
public class StockServiceImpl implements IStockService 
{
    @Autowired
    private StockMapper stockMapper;
    /**
     * 查询股票列表增删改查
     * 
     * @param id 股票列表增删改查主键
     * @return 股票列表增删改查
     */
    @Override
    public Stock selectStockById(Long id)
    {
        return stockMapper.selectStockById(id);
    }

    /**
     * 查询股票列表增删改查列表
     * 
     * @param stock 股票列表增删改查
     * @return 股票列表增删改查
     */
    @Override
    public List<Stock> selectStockList(Stock stock)
    {
        return stockMapper.selectStockList(stock);
    }

    /**
     * 新增股票列表增删改查
     * 
     * @param stock 股票列表增删改查
     * @return 结果
     */
    @Override
    public int insertStock(Stock stock)
    {
        return stockMapper.insertStock(stock);
    }

    /**
     * 修改股票列表增删改查
     * 
     * @param stock 股票列表增删改查
     * @return 结果
     */
    @Override
    public int updateStock(Stock stock)
    {
        return stockMapper.updateStock(stock);
    }

    /**
     * 批量删除股票列表增删改查
     * 
     * @param ids 需要删除的股票列表增删改查主键
     * @return 结果
     */
    @Override
    public int deleteStockByIds(Long[] ids)
    {
        return stockMapper.deleteStockByIds(ids);
    }

    /**
     * 删除股票列表增删改查信息
     * 
     * @param id 股票列表增删改查主键
     * @return 结果
     */
    @Override
    public int deleteStockById(Long id)
    {
        return stockMapper.deleteStockById(id);
    }

    @Override
    public Boolean buy(Long uid, String code, Integer num, String scokname) {
        SysUserScok sysUserScok = new SysUserScok();
        LoginUser loginUser = new TokenService().getLoginUser(ServletUtils.getRequest());
        String username = loginUser.getUsername();
        Long userid = loginUser.getUserid();
        sysUserScok.setUname(username);
        sysUserScok.setUserId(userid.intValue());
        sysUserScok.setScokPrice(sysUserScok.getScokPrice().subtract(new BigDecimal(num)));
        sysUserScok.setScokName(scokname);
//        sysUserScok.setScokId(code);
        return null;
    }
}
